<?php

    class Groups_model extends MY_Model
    {
        function __construct()
        {
            parent::__construct();
            $this->table = 'groups';
        }

        function get_html_on_group($attributes,$fields_as_string=NULL,$group_ID)
        {

            if(isset($fields_as_string)):
                $values = unserialize($fields_as_string);
                endif;

            $counter = 0;   //for tabindex
            $html = "";

            foreach ($attributes as $attribute):

            $counter++;
            $attribute_name = format_input_name($this->translate->getArray($attribute['attribute_name'],TRUE));

            $data = array(
                'title' => $this->translate->getArray($attribute['attribute_name'],TRUE),
                'id' => $group_ID.'___'.$attribute_name,
                'val' => isset($values[$group_ID.'___'.$attribute_name]) ? $values[$group_ID.'___'.$attribute_name] : NULL,
                'count' => $counter
            );

            switch ($attribute['attribute_type']) {
                case 'descriptive data':
                    $html.= $this->load->view('group_attributes/descriptive_input',$data,TRUE);
                    break;
                case 'yes/no':
                    $html.= $this->load->view('group_attributes/checkbox',$data,TRUE);
                    break;
                case 'numeric':
                    $html.= $this->load->view('group_attributes/input',$data,TRUE);
                    break;
                case 'area':
                    $html.= $this->load->view('group_attributes/input',$data,TRUE);
                    break;
                case 'distance':
                    $html.= $this->load->view('group_attributes/input',$data,TRUE);
                    break;

            }

            //$this->firephp->log($data);

            endforeach;

            //$this->firephp->log($html);

            return $html;
        }
    }

?>
